package com.ly.proxy615.dynamicsProxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;


/**
 * cglib 动态代理
 *
 */

public class CglibTest01Proxy implements MethodInterceptor {

    //private Enhancer enhancer = new Enhancer();

    //定义方法获取代理对象
    public <T>T getproxy(Class<T> cls){
        return (T) Enhancer.create(cls,this);
    }

    //重写方法实现代理操作
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("之前0"+ Arrays.toString(objects));
        Object oo = methodProxy.invokeSuper(o, objects);
        System.out.println("结束");
        return oo;
    }
}
